/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */

import java.util.Random;
import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.TimeUnit;

/**
 * <p>Project: jse2204 - T12
 * <p>Powered by webrx On 2022-09-30 17:48:15
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class T12 {
    CyclicBarrier bar = new CyclicBarrier(3,()->System.out.println("大家到起了，开饭了."));
    void eat(int t) {
        System.out.println(Thread.currentThread().getName()+"开始动身(多"+t+"秒)...");
        try {
            TimeUnit.SECONDS.sleep(t);
            System.out.println(Thread.currentThread().getName()+"到达。");
            bar.await();
            //bar.await(6,TimeUnit.SECONDS);
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (BrokenBarrierException e) {
            e.printStackTrace();
        }
    }
    public static void main(String[] args) {
        var t = new T12();
        Random rand = new Random();
        new Thread(()->t.eat(rand.nextInt(5,15)),"李四").start();
        new Thread(()->t.eat(rand.nextInt(5,15)),"张三丰").start();
        new Thread(()->t.eat(rand.nextInt(5,15)),"赵六").start();
    }
}
